﻿using System;
using System.Collections.Generic;
using CtCommon.Utility;
using CtUser.Utility.Validate;

namespace Ct.StudentProject.DTO
{
    public class RequestStudent
    {
        public string userName { get; set; }
        public string name { get; set; }
        public string IDNumber { get; set; }
        public int Sex { get; set; }
        public string Password { get; set; }

        public RequestStudent(string usrName, string name, string IDnumber, string Password)
        {
            this.userName = usrName;
            this.name = name;
            this.IDNumber = IDnumber;
            this.Password = Password;
        }
        public bool VerifyInfo(out string errmsg)
        {
            errmsg = "success";
            bool isvaild = this.userName.InitValidation().ToNext(!this.name.IsNullOrEmptyAndTrim()).IsTrue("nameEmpty")
                     .ToNext(!this.userName.IsNullOrEmptyAndTrim()).IsTrue("userNameEmpty")
                    .ToNext(!this.IDNumber.IsNullOrEmptyAndTrim()).IsTrue("IDNumberEmpty")
                    .ToNext(this.name.IsChinese()).IsTrue("nameIsNotChinese")
                    .ToNext(this.IDNumber.IsIDCard()).IsTrue("errIDcard").End(out string msg);

            errmsg = msg;
            return isvaild;
        }

        public static bool VerifyAndDeliver(RequestStudent stu, out string msg_result)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("nameEmpty", "姓名为空");
            dic.Add("userNameEmpty", "用户名为空");
            dic.Add("IDNumberEmpty", "身份证信息不能为空");
            dic.Add("nameIsNotChinese", "姓名必须用中文填写");
            dic.Add("errIDcard", "错误身份证号码");
            dic.Add("success", "注册成功");


            string msg = string.Empty;
            stu.VerifyInfo(out msg);
            foreach (var info in dic)
            {
                if (info.Key == msg)
                {
                    msg_result = info.Value;
                    return false;
                }
            }
            msg_result = "注册成功";
            return true;
        }
    }

}

//Dictionary<string, string> dic = new Dictionary<string, string>();
//dic.Add("nameEmpty", "姓名为空");
//        dic.Add("userNameEmpty", "用户名为空");
//        dic.Add("IDNumberEmpty", "身份证不能为空");